
###
### DECENT LIVING STANDARDS MAPPING 
### 

###
### DESCRIPTIVE GRAPHS 
### 

rm(list=ls())#; .rs.restartR()


##
## PACKAGES --------------------------------------------------------------
##

library(tidyverse)
library(countrycode)
library(stringr)
library(data.table)
library(texreg)
library(sandwich)
library(margins)
library(ggpubr)

##
## LOADING DATA ----------------------------------------------------------
##

load(file="Gaps in DLS achievement_worldregion level.RData")

g2 <- dls_worldregion %>% 
  select(worldregion, contains("diff")) %>% 
  gather(contains("diff"), key=dimension,value=value) %>% 
  mutate(dimension=recode(dimension,
         "diff_housing"="Housing",
          "diff_thermal"="Thermal",
          "diff_nutrition"="Nutrition",
          "diff_foodprep"="Food",
          "diff_water"="Water",
          "diff_sanitation"="Sanitation",
          "diff_health"="Health",
          "diff_education"="Education",
          "diff_socialconnect"="Social",
          "diff_physicialconnect"="Physical")) %>% 
  ggplot(mapping=aes(x=fct_reorder(dimension, -value),  y=value))  +
  geom_bar(stat="identity",  fill="#e6f0ef", color="black") + 
  facet_wrap(vars(worldregion), nrow=2, ncol=3)+
  theme_bw()+
  theme(axis.text.x = element_text(angle=45, hjust=1),
        legend.position = "bottom",
        legend.text = element_text(size=13),
        axis.text=element_text(size=12),
        axis.title = element_text(size=14),
        strip.background =element_rect(fill="white"),
        strip.text = element_text(size=12, colour = 'black', face='bold'))+
  scale_y_continuous(labels=scales::percent)+
  xlab("Potential for closing gap in DLS dimensions")+ylab("% gain in population share with access to >2/3 DLS 
dimensions if gap in one DLS dimension is closed")+
  ggtitle("")

g2

save(g2, file="figure 2b.RData")

load("figure 2a.RData")

g12 <- ggarrange(g1, g2, nrow=2, 
                 heights=c(1.4,1), 
                 labels=c("A","B"),
                 hjust=c(0,0),
                 vjust=c(1,1),
                 font.label=list(size=25))
g12

ggsave(g12, filename="figure 2.png", width=12, height=14.0)
ggsave(g12, filename="figure 2.svg", width=12, height=14.0)
